#!/usr/bin/env python
# coding=utf-8
# __author__ = 'Yunchao Ling'

cn_names = {}

print("Loading chinese item names.")
infile = open("/Users/genesis/Seafile/私人资料库/GameSave/mhr/cn_names.txt", "r", encoding="gb2312")
infile.readline()
for line in infile:
    line = line.rstrip("\n")
    splitline = line.split("\t")
    if not splitline[0].startswith("#Rejected#"):
        if splitline[3] != "":
            cn_names[splitline[0]] = splitline[3]
infile.close()

# for item in cn_names:
#     print("%s\t%s" % (item,cn_names[item]))

print("Generating new item file.")
infile = open("/Users/genesis/Seafile/私人资料库/GameSave/mhr/items_English.csv", "r", encoding="gb2312")
outfile = open("/Users/genesis/Seafile/私人资料库/GameSave/mhr/items_Chinese.csv", "w", encoding="gb2312")
for line in infile:
    line = line.rstrip("\n")
    splitline = line.split(",")
    if splitline[2] in cn_names:
        outfile.write("%s,%s,%s\n" % (splitline[0], splitline[1], cn_names[splitline[2]]))
    else:
        outfile.write(line + "\n")
    outfile.flush()
infile.close()
outfile.close()
